package me.shurufa.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * 应用数据库 目前版本1 包含消息列表与会话列表
 * 【废弃】
 *
 * @FileName: me.shurufa.db.DatabaseHelper.java
 * @author: kHRYSTAL
 * @email: 723526676@qq.com
 * @date: 2016-01-25 10:08
 */
public class DatabaseHelper extends SQLiteOpenHelper{
    /**
     * 版本号
     */
    private static final int DB_VERSION = 1;

    public DatabaseHelper(Context context, String name) {
        super(context, name, null, DB_VERSION);
    }

    /**
     * 首次执行 创建表
     * @param db
     */
    @Override
    public void onCreate(SQLiteDatabase db) {
        db.beginTransaction();
        createTables(db);
        db.setTransactionSuccessful();
        db.endTransaction();
    }

    private void createTables(SQLiteDatabase db) {
        //会话消息表
        db.execSQL("CREATE TABLE IF NOT EXISTS srf_dialogs (_id INTEGER PRIMARY KEY,"
                + " uid INTEGER NOT NULL, nick TEXT, pic TEXT, last_text TEXT, "
                + "last_time INTEGER, badge INTEGER, fullLoaded BOOL);");
        //消息内容
        db.execSQL("CREATE TABLE IF NOT EXISTS srf_messages "
                + "(_id INTEGER PRIMARY KEY, did INTEGER NOT NULL, "
                + "uid INTEGER NOT NULL, text TEXT, hash TEXT, time INTEGER, UNIQUE(uid, hash));");

        db.execSQL("CREATE TABLE IF NOT EXISTS srf_kvs (_id INTEGER PRIMARY KEY, s_int INTEGER, s_des TEXT)");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
